package com.jeewms.www.tms.ui.acitivity;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.AbsListView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.VolleyError;
import com.bumptech.glide.Glide;
import com.jeewms.www.tms.AutoReceiver;
import com.jeewms.www.tms.Receiver;
import com.jeewms.www.tms.base.BaseBackActivity;
import com.jeewms.www.tms.bean.vm.Ginfo;
import com.jeewms.www.tms.R;
import com.jeewms.www.tms.base.BaseActivity;
import com.jeewms.www.tms.bean.listvm.DemoListVm;
import com.jeewms.www.tms.bean.vm.wmapiUtil.ResultDO;
import com.jeewms.www.tms.util.EditChangedListener;
import com.jeewms.www.tms.util.GsonUtils;
import com.jeewms.www.tms.util.Logutil;
import com.jeewms.www.tms.util.UpdataUiUtil;
import com.jeewms.www.tms.util.listviewanimations.itemmanipulation.OnDismissCallback;
import com.jeewms.www.tms.util.z_toast;
import com.jeewms.www.tms.volley.HTTPUtils;
import com.jeewms.www.tms.volley.VolleyListener;

import java.util.ArrayList;
import java.util.List;
import com.jeewms.www.tms.bean.vm.MyImageView;

import org.greenrobot.eventbus.EventBus;

import butterknife.ButterKnife;
import butterknife.OnClick;

public class Matnr_Activity extends BaseBackActivity {
    private TextView btn = null;
    String tag;
    ListView mLvGent;
    List<Ginfo> mginfo;


    //  GINfo madaper;
    private int titlebar_back;
    public static void show(Context context) {
        Intent intent = new Intent(context, Matnr_Activity.class);
        context.startActivity(intent);

    }

    protected void initView() {
        super.initView();
        //  ButterKnife.bind(this);
        //  EventBus.getDefault().register(this);
        Logutil.print("测试System的使用LOGCAT");
        setTitle("物料信息查询");
        final EditText et_fangweima = (EditText) findViewById(R.id.et_fangweima);
      //  et_fangweima.addTextChangedListener(new EditChangedListener(et_fangweima));
        //新增加载网络图片示例
   //     ImageView myImageView =findViewById(R.id.tv_tp1);
    //   UpdataUiUtil.getDefaul().setImage(getActivity(),"http://txt22263.book118.com/2017/0509/book105460/105459445.jpg",myImageView);
        //加载gif
    //    UpdataUiUtil.getDefaul().setImage(getActivity(),R.drawable.timg2,myImageView);
        btn = (TextView) findViewById(R.id.tv_search);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                //实现广播 modify by it_ysye  2018/10/10
              //  Intent intent = new Intent();
//                Intent intent = new Intent(getApplicationContext(), AutoReceiver.class);
//                intent.setAction("VIDEO_TIMER");
//                intent.putExtra("name", "xiazdong");
//                Matnr_Activity.this.sendBroadcast(intent);
//                Toast.makeText(getApplicationContext(), "发送广播成功", Toast.LENGTH_SHORT).show();
//         //       实现广播 modify by it_ysye  2018/10/10
//                Log.i("广播","成功");
                getData();
            }
        });
    }


    private void getData() {
      //

        final EditText et_fangweima1 = (EditText) findViewById(R.id.et_fangweima);
        Logutil.print("输入查找条件"+et_fangweima1.getText().toString());
        z_toast ts = new z_toast();
        if (TextUtils.isEmpty(et_fangweima1.getText().toString())) {

            ts.showToast("物料号或者防伪码不能为空",Matnr_Activity.this);
            return;
        }

         String url = "http://192.168.200.100/zzwms/rest/wmbaseapi/getgoodsdetail/"+ et_fangweima1.getText().toString();
       // String url = "http://172.17.210.197:8080/zzwms/rest/wmapi/getdoc/KCCX"
        Logutil.print("url" + url);
        HTTPUtils.get(getActivity(), url, new VolleyListener() {
            @Override
            public void onResponse(String response) {
                Logutil.print("res==" + response);
                ResultDO vm = GsonUtils.parseJSON(response, ResultDO.class);
                String s = null;
                mginfo = new ArrayList<Ginfo>();
                if (vm.getObj() == null) {
                    z_toast ts = new z_toast();
                        ts.showToast("后台数据返回空值",Matnr_Activity.this);
                        return;

                } else {
                    for (int i = 0; i < vm.getObj().size(); i++) {
                        //    Ginfo bean = new Ginfo();
                     //   s = (vm.getObj().get(i).getWmX2());
                        TextView et_matnr = (TextView) findViewById(R.id.et_matnr);
                        et_matnr.setText(vm.getObj().get(i).getWmX2());

                        TextView et_pp = (TextView) findViewById(R.id.et_pp);
                        et_pp.setText(vm.getObj().get(i).getWmX1());

                        TextView et_zkh = (TextView) findViewById(R.id.et_zkh);
                        et_zkh.setText(vm.getObj().get(i).getWmX3());
                        TextView et_zsh = (TextView) findViewById(R.id.et_zsh);
                        et_zsh.setText(vm.getObj().get(i).getWmX4());
                        TextView et_maktx = (TextView) findViewById(R.id.et_maktx);
                        et_maktx.setText(vm.getObj().get(i).getWmX7());

                    //    ImageView tv_tp = (ImageView)findViewById(R.id.tv_tp);
                      //  tv_tp.setImageURL("http://192.168.254.123/sms/Pic?pic=BL6052D11.JPG");

                         MyImageView myImageView = (MyImageView)findViewById(R.id.tv_tp);
                      //  myImageView.setImageURL("http://192.168.254.123/sms/Pic?pic=BL6052D11.JPG");
                    //    UpdataUiUtil.getDefaul().setImage(getActivity(),"http://192.168.254.123/sms/Pic?pic=BL6052D11.JPG",myImageView);
                        myImageView.setImageURL(vm.getObj().get(i).getWmX6());
                        //     bean.setBinId(vm.getObj().get(i).getX6());
                        //     bean.setMaktx(vm.getObj().get(i).getX8());
                        //     mginfo.add(bean);
                        //    Logutil.print("mginfo.size()2="+mginfo.size());
                    }
                }
            }

            @Override
            public void onErrorResponse(VolleyError error) {
                Toast sk = Toast.makeText(Matnr_Activity.this, "查询失败!",Toast.LENGTH_LONG);
                sk.show() ;
            }
        });


    }


    protected int getContentResId() {
        return R.layout.activity_matnr;
    }
}





